<?php
	require 'Slim/Slim.php';
	\Slim\Slim::registerAutoloader();
	spl_autoload_register(function ($class) {
		include $class . '.class.php';
	});


	$app = new \Slim\Slim();
	$app->notFound(function () use ($app) {
		$app->halt(404);
	});

	$app->group('/item', function () use ($app) {

		$app->get('/:id', function ($id) use ($app){
			$item = Item::getItemForId($id, true);
			if($item){
				echo json_encode($item);
			}
			else $app->notFound();
		});

		$app->get('/search/:query', function ($query) {
		});
	});

	$app->group('/debug', function() use ($app){
		$app->get('/:id', function ($id) use ($app){
			$recipe = Recipe::getRecipeForId($id);
			if($recipe) echo json_encode($recipe);
			else $app->notFound();
		});
	});

	$app->run();
?>
